package com.chenshu.mobile_test.controller;

import com.chenshu.mobile_test.common.MyResponse;
import com.chenshu.mobile_test.service.MobileService;
import com.chenshu.mobile_test.service.MobileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-05-08
 * Time：09:13
 */
@RestController
@CrossOrigin
public class MobileController {

    @Autowired
    MobileService mobileService;

    @RequestMapping("/mobile")
    public Object getMobile(String phone) {
        if (!StringUtils.hasLength(phone)) {
            return MyResponse.fail(-2, "您输入的手机号为空!");
        }
        HashMap<String, String> resultData = mobileService.getBelonging(phone);
        if (!StringUtils.hasLength(resultData.get("province"))
                || !StringUtils.hasLength(resultData.get("city"))
                || !StringUtils.hasLength(resultData.get("sp"))) {
            return MyResponse.fail(-3, "未查询到您手机号的归属地");
        }
        return MyResponse.success(resultData, "获取手机号归属地成功!");
    }
}
